const roleService = require('../../service/roleService')

var express = require('express');
var router = new express.Router();


router.get('/list',function(req,res){

 roleService.list(function(rows){
    res.json(rows)
 })
})

router.post('/add',function(req,res){

    let role = {
         role_name:req.body.role_name,
         is_used:req.body.is_used
    }

    console.log(req.body);

   let responseMsg = {
       flag:false
   }

    roleService.add(role,function(result){

        
        if(result.affectedRows>0){
                responseMsg.flag = true;
        }

        res.json(responseMsg);
    })
     
})

router.post('/edit',function(req,res){

    let role = {
        role_id:req.body.role_id,
        role_name:req.body.role_name,
        is_used:req.body.is_used
   }


   let responseMsg = {
    flag:false
}

 roleService.edit(role,function(result){

     if(result.affectedRows>0){
             responseMsg.flag = true;
     }
     res.json(responseMsg);
 })
})




router.post('/remove',function(req,res){

    let role = {
        role_id:req.body.role_id
   }


   let responseMsg = {
    flag:false
}

 roleService.remove(role,function(result){

     if(result.affectedRows>0){
             responseMsg.flag = true;
     }
     res.json(responseMsg);
 })
})



module.exports = router;